github.com/bencicandrej/quorum@v2.2.6-0.20190909091323-878cab86f711+incompatible/docs/Getting Started/7Nodes-Setup.md (about)

     1  # Setting up the 7nodes example
     2  
     3  ## Installation
     4  Clone the [`quorum-examples`](https://github.com/jpmorganchase/quorum-examples.git) repo. 
     5  
     6  ```bash
     7  git clone https://github.com/jpmorganchase/quorum-examples.git
     8  ```
     9  
    10  !!! Warning
    11      Any account/encryption keys used in the quorum-examples repo are for demonstration and testing purposes only. Before running a real environment, new keys should be generated using Geth's `account` tool, Tessera's `-keygen` option, and Constellation's `--generate-keys` option
    12  
    13  ## Prepare your environment
    14  
    15  A 7 node Quorum network must be running before the example can be run.  The [`quorum-examples`](https://github.com/jpmorganchase/quorum-examples.git) repo provides the means to create a pre-configured sample network in minutes.  
    16  
    17  There are 3 ways to start the sample network, each method is detailed below:
    18  
    19  1. By running a pre-configured Vagrant virtual-machine environment which comes complete with Quorum, Constellation, Tessera and the 7nodes example already installed.  Bash scripts provided in the examples are used to create the sample network.
    20  1. By running [`docker-compose`](https://docs.docker.com/compose/) against a [preconfigured `compose` file](https://github.com/jpmorganchase/quorum-examples/blob/master/docker-compose.yml) to create the sample network
    21  1. By installing Quorum and Tessera/Constellation locally and using bash scripts provided in the examples to create the sample network
    22  
    23  Your environment must be prepared differently depending on the method being used to run the example.
    24  
    25  ### Running with Vagrant
    26  1. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
    27  2. Install [Vagrant](https://www.vagrantup.com/downloads.html)
    28  3. Download and start the Vagrant instance (note: running `vagrant up` takes approx 5 mins):
    29  
    30      ```sh
    31      git clone https://github.com/jpmorganchase/quorum-examples
    32      cd quorum-examples
    33      vagrant up
    34      vagrant ssh
    35      ```
    36  
    37  4. To shutdown the Vagrant instance, run `vagrant suspend`. To delete it, run
    38     `vagrant destroy`. To start from scratch, run `vagrant up` after destroying the
    39     instance.
    40  
    41  #### Troubleshooting Vagrant
    42  * If you are behind a proxy server, please see https://github.com/jpmorganchase/quorum/issues/23.
    43  * If you are using macOS and get an error saying that the ubuntu/xenial64 image doesn't
    44  exist, please run `sudo rm -r /opt/vagrant/embedded/bin/curl`. This is usually due to
    45  issues with the version of curl bundled with Vagrant.
    46  * If you receive the error `default: cp: cannot open '/path/to/geth.ipc' for reading: Operation not supported` after running `vagrant up`, run `./raft-init.sh` within the 7nodes directory on your local machine.  This will remove temporary files created after running 7nodes locally and will enable `vagrant up` to execute correctly.  
    47  
    48  #### Troubleshooting Vagrant: Memory usage
    49  * The Vagrant instance is allocated 6 GB of memory.  This is defined in the `Vagrantfile`, `v.memory = 6144`.  This has been deemed a suitable value to allow the VM and examples to run as expected.  The memory allocation can be changed by updating this value and running `vagrant reload` to apply the change.
    50  
    51  * If the machine you are using has less than 8 GB memory you will likely encounter system issues such as slow down and unresponsiveness when starting the Vagrant instance as your machine will not have the capacity to run the VM.  There are several steps that can be taken to overcome this:
    52      1. Shutdown any running processes that are not required
    53      1. If running the [7nodes example](../7Nodes), reduce the number of nodes started up.  See the [7nodes: Reducing the number of nodes](../7Nodes-Setup#reducing-the-number-of-nodes) for info on how to do this.
    54      1. Set up and run the examples locally.  Running locally reduces the load on your memory compared to running in Vagrant.
    55  
    56  ### Running with Docker
    57  
    58  1. Install Docker (https://www.docker.com/get-started)
    59      - If your Docker distribution does not contain `docker-compose`, follow [this](https://docs.docker.com/compose/install/) to install Docker Compose
    60      - Make sure your Docker daemon has at least 4G memory
    61      - Required Docker Engine 18.02.0+ and Docker Compose 1.21+
    62  1. Download and run `docker-compose`
    63     ```sh
    64     git clone https://github.com/jpmorganchase/quorum-examples
    65     cd quorum-examples
    66     docker-compose up -d
    67     ```
    68  1. By default, the Quorum network is created with Tessera privacy managers and Istanbul BFT consensus. To use Raft consensus, set the environment variable `QUORUM_CONSENSUS=raft` before running `docker-compose`
    69     ```sh
    70     QUORUM_CONSENSUS=raft docker-compose up -d
    71     ```
    72  1. Run `docker ps` to verify that all quorum-examples containers (7 nodes and 7 tx managers) are **healthy**
    73  1. Run `docker logs <container-name> -f` to view the logs for a particular container
    74  1. __Note__: to run the 7nodes demo, use the following snippet to open `geth` Javascript console to a desired node (using container name from `docker ps`) and send a private transaction
    75     ```sh
    76     $ docker exec -it quorum-examples_node1_1 geth attach /qdata/dd/geth.ipc
    77     Welcome to the Geth JavaScript console!
    78  
    79     instance: Geth/node1-istanbul/v1.7.2-stable/linux-amd64/go1.9.7
    80     coinbase: 0xd8dba507e85f116b1f7e231ca8525fc9008a6966
    81     at block: 70 (Thu, 18 Oct 2018 14:49:47 UTC)
    82      datadir: /qdata/dd
    83      modules: admin:1.0 debug:1.0 eth:1.0 istanbul:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
    84  
    85     > loadScript('/examples/private-contract.js')
    86     ```
    87  1. Shutdown Quorum Network
    88     ```sh
    89     docker-compose down
    90     ```
    91  
    92  #### Troubleshooting Docker
    93  
    94  1. Docker is frozen
    95      - Check if your Docker daemon is allocated enough memory (minimum 4G)
    96  1. Tessera crashes due to missing file/directory
    97      - This is due to the location of `quorum-examples` folder is not shared
    98      - Please refer to Docker documentation for more details:
    99          - [Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/troubleshoot/#shared-drives)
   100          - [Docker Desktop for Mac](https://docs.docker.com/docker-for-mac/#file-sharing)
   101          - [Docker Machine](https://docs.docker.com/machine/overview/): this depends on what Docker machine provider is used. Please refer to its documentation on how to configure shared folders/drives
   102  1. If you run Docker inside Docker, make sure to run the container with `--privileged`
   103  
   104  ### Running locally
   105  
   106  !!! info
   107      Quorum must be run on Ubuntu-based/macOS machines.  Constellation can only be run on Ubuntu-based machines.  Running the examples therefore requires an Ubuntu-based/macOS machine.  If running the examples using Constellation then an Ubuntu-based machine is required. 
   108  
   109  1. Install [Golang](https://golang.org/dl/)
   110  2. Download and build [Quorum](https://github.com/jpmorganchase/quorum/):
   111     
   112      ```sh
   113      git clone https://github.com/jpmorganchase/quorum
   114      cd quorum
   115      make
   116      GETHDIR=`pwd`; export PATH=$GETHDIR/build/bin:$PATH
   117      cd ..
   118      ```
   119      
   120  3. Download and build Tessera (see [README](https://github.com/jpmorganchase/tessera) for build options)
   121     
   122      ```bash
   123      git clone https://github.com/jpmorganchase/tessera.git
   124      cd tessera
   125      mvn install
   126      ```
   127      
   128  4. Download quorum-examples
   129      ```sh
   130      git clone https://github.com/jpmorganchase/quorum-examples
   131      ```
   132  
   133  ## Starting the 7nodes sample network
   134  
   135  !!! info
   136      This is not required if `docker-compose` has been used to prepare the network as the `docker-compose` command performs these actions for you
   137      
   138  Shell scripts are included in the examples to make it simple to configure the network and start submitting transactions.
   139  
   140  All logs and temporary data are written to the `qdata` folder.
   141  
   142  The sample network can be created to run using Istanbul BFT, Raft or Clique POA consensus mechanisms.  In the following commands replace `{consensus}` with one of `raft`, `istanbul` or `clique` depending on the consensus mechanism you want to use.
   143  
   144  1. Navigate to the 7nodes example directory, configure the Quorum nodes and initialize accounts & keystores:
   145      ```sh
   146      cd path/to/7nodes
   147      ./{consensus}-init.sh
   148      ```
   149  1. Start the Quorum and privacy manager nodes (Constellation or Tessera):
   150      - If running in Vagrant:
   151          ```sh
   152          ./{consensus}-start.sh
   153          ```
   154          By default, Tessera will be used as the privacy manager.  To use Constellation run the following:
   155          ```
   156          ./{consensus}-start.sh constellation
   157          ```
   158  
   159      - If running locally:
   160          ```
   161          ./{consensus}-start.sh tessera --tesseraOptions "--tesseraJar /path/to/tessera-app.jar"
   162          ```
   163          
   164          By default, `{consensus}-start.sh` will look in `/home/vagrant/tessera/tessera-app/target/tessera-app-{version}-app.jar` for the Tessera jar.  `--tesseraOptions` must be provided so that the start script looks in the correct location for the Tessera jar: 
   165  
   166          Alternatively, the Tessera jar location can be specified by setting the environment variable `TESSERA_JAR`.
   167  
   168  1. You are now ready to start sending private/public transactions between the nodes
   169  
   170  1. To stop the network:
   171      ```bash
   172      ./stop.sh
   173      ``` 
   174  
   175  ## Running the example
   176  `quorum-examples` includes some simple transaction contracts to demonstrate the privacy features of Quorum.  See the [7nodes Example](../7Nodes) page for details on how to run them.
   177  
   178  ## Variations
   179  ### Reducing the number of nodes 
   180  It is easy to reduce the number of nodes used in the example network.  You may want to do this for memory usage reasons or just to experiment with a different network configuration.
   181  
   182  For example, to run the example with 5 nodes instead of 7, the following changes need to be made:
   183  
   184  1. Reduce number of nodes being started
   185      1. In `{consensus}-start.sh`:
   186  
   187          Comment out the following lines used to start Quorum nodes 6 & 7
   188              ```sh
   189              # PRIVATE_CONFIG=qdata/c6/tm.ipc nohup geth --datadir qdata/dd6 $ARGS --raftport 50406 --rpcport 22005 --port 21005 --unlock 0 --password passwords.txt 2>>qdata/logs/6.log &
   190              # PRIVATE_CONFIG=qdata/c7/tm.ipc nohup geth --datadir qdata/dd7 $ARGS --raftport 50407 --rpcport 22006 --port 21006 --unlock 0 --password passwords.txt 2>>qdata/logs/7.log &
   191              ```
   192      
   193      1. In `constellation-start.sh` or `tessera-start.sh` (depending on which privacy manager you are using): 
   194      
   195          Change the 2 instances of `for i in {1..7}` to `for i in {1..5}`
   196      
   197  1. `private-contract.js` by default sends a transaction to node 7.  As node 7 will no longer be started this must be updated to instead send to node 5:
   198  
   199      1. Copy node 5's public key from `./keys/tm5.pub`
   200      
   201      2. Replace the existing `privateFor` in `private-contract.js` with the key copied from `tm5.pub` key, e.g.:
   202          ``` javascript
   203          var simple = simpleContract.new(42, {from:web3.eth.accounts[0], data: bytecode, gas: 0x47b760, privateFor: ["R56gy4dn24YOjwyesTczYa8m5xhP6hF2uTMCju/1xkY="]}, function(e, contract) {...}
   204          ```
   205  
   206  1. Update the list of nodes involved in consensus
   207      * If using Raft
   208          1. Remove node 6 and node 7's enode addresses from `permissioned-nodes.json` (i.e. the entries with `raftport` `50406` and `50407`)
   209      * If using IBFT
   210          1. Find the 20-byte address representations of node 6 and node 7's nodekey (nodekeys located at `qdata/dd{i}/geth/nodekey`).  There are many ways to do this, one is to run a script making use of `ethereumjs-wallet`:
   211              ```node
   212              const wlt = require('ethereumjs-wallet');
   213              
   214              var nodekey = '1be3b50b31734be48452c29d714941ba165ef0cbf3ccea8ca16c45e3d8d45fb0';
   215              var wallet = wlt.fromPrivateKey(Buffer.from(nodekey, 'hex'));
   216              
   217              console.log('addr: ' + wallet.getAddressString());
   218              ```
   219          1. Use `istanbul-tools` to decode the `extraData` field in `istanbul-genesis.json`
   220              ```bash
   221              git clone https://github.com/jpmorganchase/istanbul-tools.git
   222              cd istanbul-tools
   223              make
   224              ./build/bin/istanbul extra decode --extradata <...>
   225              ```
   226          1. Copy the output into a new `.toml` file and update the formatting to the following:
   227              ```yaml
   228              vanity = "0x0000000000000000000000000000000000000000000000000000000000000000"
   229              validators = [
   230                "0xd8dba507e85f116b1f7e231ca8525fc9008a6966",
   231                "0x6571d97f340c8495b661a823f2c2145ca47d63c2",
   232                ...
   233              ]
   234              ```
   235          1. Remove the addresses of node 6 and node 7 from the validators list 
   236          1. Use `istanbul-tools` to encode the `.toml` as `extraData`
   237              ```bash
   238              ./build/bin/istanbul extra encode --config /path/to/conf.toml
   239              ```
   240          1. Update the `extraData` field in `istanbul-genesis.json` with output from the encoding 
   241  
   242  After making these changes, the `{consensus}-init.sh`, `{consensus}-start.sh`, and `./runscript.sh private-contract.js` scripts can be run as normal.  You can then follow steps described above to verify that node 5 can see the transaction payload and that nodes 2-4 are unable to see the payload.
   243  
   244  ### Using a Tessera remote enclave
   245  Tessera v0.9 introduced the ability to run the privacy manager's enclave as a separate process from the Transaction Manager. This is a more secure way of being able to manage and interact with your keys.  
   246  
   247  To start a sample 7nodes network that uses remote enclaves run `./{consensus}-start.sh tessera-remote`. By default this will start 7 Transaction Managers, the first 4 of which use a remote enclave. If you wish to change this number, you will need to add the extra parameter `--remoteEnclaves X` in the `--tesseraOptions`, e.g. `./{consensus}-start.sh tessera-remote --tesseraOptions "--remoteEnclaves 7"`.